
// roleCode
export const getRoleCode = function (userInfo) {
  const postName = userInfo.postName || ''
  let roleCode = ''
  if (postName.includes('学生') || postName.includes('班长') || postName.includes('学习委员')) {
    roleCode = 'student'
  } else if (postName.includes('家长')) {
    roleCode = 'parent' // 'parent'
  } else if (postName.includes('老师') || postName.includes('咨询师') || postName.includes('专家') || postName.includes('心理')) {
    roleCode = 'teacher'
  } else {
    // 其他校长等角色
    roleCode = 'other' // 'other'
  }
  return roleCode
}

// 待办事项数量封装
export const parseTodoData = function (data = {}, userInfo) {
  let total = 0
  Object.keys(data).forEach((key) => (total += Number(data[key])))
  let roleCode = getRoleCode(userInfo)
  let dataArr = []
  // 当前角色
  if (
    roleCode === 'student' ||
    roleCode === 'parent' ||
    roleCode === 'teacher' ||
    roleCode === 'other'
  ) {
    dataArr.push({
      key: 'evaluation',
      name: '学生测评',
      qty: data['evaluationTotal'] || 0, // 未完成的数量
    })
  }
  if (roleCode === 'teacher' || roleCode === 'other') {
    dataArr.push({
      key: 'warn',
      name: '学生预警',
      qty: data['warnTotal'] || 0, // 未完成的数量
    })
  }
  if (roleCode === 'teacher') {
    // dataArr.push({
    //   key: 'reserve',
    //   name: '学生预约',
    //   qty: data['markTotal'] || 0, // 未完成的数量
    // })
  }
  let op = {
    qty: total, // 总待办数量
    data: dataArr,
  }
  return op
}

